﻿#pragma once
#include <QToolBar>
#include <QToolButton>
#include <QMenu>
#include <QAction>
#include <QObject>

// 辅助类：用于在不同窗口设置用户中心菜单和按钮
class UserCenterMenuHelper {
public:
    // 设置用户中心菜单和按钮到工具栏
    static void SetupUserCenterMenu(QToolBar* toolbar,
                                    QAction* userCenterAction,
                                    QMenu* userCenterMenu) {
        // 移除原有的用户中心按钮（QAction），防止重复
        QList<QAction*> actions = toolbar->actions();
        for (QAction* act : actions) {
            if (act == userCenterAction) {
                toolbar->removeAction(act);
                break;
            }
        }
        // 创建 QToolButton 作为“用户中心”按钮
        QToolButton* userCenterButton = new QToolButton(toolbar);
        userCenterButton->setText(userCenterAction->text());
        userCenterButton->setDefaultAction(userCenterAction);
        userCenterButton->setMenu(userCenterMenu);
        userCenterButton->setPopupMode(QToolButton::InstantPopup);
        userCenterButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
        toolbar->addWidget(userCenterButton);
    }
};
